using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Microsoft.Practices.CompositeUI.SmartParts;

namespace SCSFContrib.CompositeUI.WPF.Workspaces
{
	/// <summary>
	/// A specialized <see cref="Microsoft.Practices.CompositeUI.SmartParts.WorkspaceComposer{TSmartPart, TSmartPartInfo}"/> that exposes a
	/// writable collection of smart parts in the workspace via the <see cref="InnerSmartParts"/> property.
	/// </summary>
	/// <remarks>
	/// <para>
	/// This class is only required because <see cref="Microsoft.Practices.CompositeUI.SmartParts.WorkspaceComposer{TSmartPart, TSmartPartInfo}"/>
	/// does not expose smart parts in a writable fashion as does the base <see cref="Workspace{TSmartPart, TSmartPartInfo}"/> implementation.
	/// </para>
	/// <para>
	/// Note that the <see cref="InnerSmartParts"/> property is of type <see cref="IList{TSmartPart}"/> even though the base class exposes only an
	/// instance of type <see cref="ICollection{TSmartPart}"/>. This is done by dynamic casting and thus relies on an implementation detail of
	/// <see cref="Microsoft.Practices.CompositeUI.SmartParts.WorkspaceComposer{TSmartPart, TSmartPartInfo}"/>. This is required for performance
	/// reasons since various workspace implementations would need to rebuild the collection frequently without list-style access.
	/// </para>
	/// </remarks>
	/// <typeparam name="TSmartPart">
	/// The type of smart parts supported by the workspace.
	/// </typeparam>
	/// <typeparam name="TSmartPartInfo">
	/// The type of the smart part information received by the workspace.
	/// </typeparam>
	internal sealed class WorkspaceComposer<TSmartPart, TSmartPartInfo> : Microsoft.Practices.CompositeUI.SmartParts.WorkspaceComposer<TSmartPart, TSmartPartInfo>
		where TSmartPartInfo : ISmartPartInfo, new()
	{
		/// <summary>
		/// Gets the collection of smart parts being maintained by this workspace composer.
		/// </summary>
		public new IList<TSmartPart> InnerSmartParts
		{
			get
			{
				Debug.Assert(base.InnerSmartParts is IList<TSmartPart>, "base.InnerSmartParts must be of type IList<TSmartPart>.");
				return base.InnerSmartParts as IList<TSmartPart>;
			}
		}

		/// <summary>
		/// Constructs an instance of <c>WorkspaceComposer</c>.
		/// </summary>
		/// <param name="composedWorkspace"></param>
		public WorkspaceComposer(IComposableWorkspace<TSmartPart, TSmartPartInfo> composedWorkspace)
			: base(composedWorkspace)
		{
		}
	}
}
